package com.xiaoxiong.text;

import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Handler;

public class GetPersonInfo {
	private String url = SchoolUrl.PersonInfo;
	private Context context;
	private Handler personHandler;
	private String cookie;
	private SharedPreferences nb_message;
	private SharedPreferences cookie_message;
	private StringHttp stringHttp;

	public GetPersonInfo(Context context, Handler personHandler) {
		super();
		this.context = context;
		this.personHandler = personHandler;
		this.stringHttp = new StringHttp(this.context);
		cookie_message = context.getSharedPreferences("test", Context.MODE_PRIVATE);
		//获取学生id
		nb_message = context.getSharedPreferences("postload", Context.MODE_PRIVATE);
		url += nb_message.getString("personinfoid", null);
		this.getCookie();
	}

	// 获取cookies
	private void getCookie() {
		cookie = cookie_message.getString("logincookie", null);
		// 由于取出cookie是包含KEY的，所以要去掉
		StringBuilder sb = new StringBuilder(cookie);
		sb.delete(sb.indexOf(";"), sb.length());
		sb.delete(0, sb.indexOf("=") + 1);
		cookie = sb.toString();
	}
	
	public void Post() {

		/**
		 * 因为登录过，所以获取个人信息只需要提交登录成功时服务器返回的cookies参数即可
		 */
		Map<String, String> postDatas = new HashMap<String, String>();
		postDatas.put("JSESSIONID", cookie);
		stringHttp.Post(url, personHandler, postDatas);
	}
}
